jQuery("#asset").select2().trigger("change");
jQuery("#applyArea").select2().trigger("change");
function OfficeMoneyAllSum() {
	var sum = 0;
	var a1 = jQuery('#rentMoney').val()==""?0:jQuery('#rentMoney').val();
	var a2 = jQuery('#waterMoney').val()==""?0:jQuery('#waterMoney').val();
	var a3 = jQuery('#wuguanMoney').val()==""?0:jQuery('#wuguanMoney').val();
	var a4 = jQuery('#banTelephoneMoney').val()==""?0:jQuery('#banTelephoneMoney').val();
	var a5 = jQuery('#shoppingMoney').val()==""?0:jQuery('#shoppingMoney').val();
	var a6 = jQuery('#otherMoney').val()==""?0:jQuery('#otherMoney').val();
	sum = parseFloat(a1) + parseFloat(a2)+parseFloat(a3) + parseFloat(a4)+parseFloat(a5) + parseFloat(a6);
	jQuery('#OfficeMoneyAll').val(sum);
	jQuery('#officeMoney').val(sum);
	OtherMoneyAllSum();
}
function CarMoneyAllSum() {
	var sum = 0;
	var a1 = jQuery('#insuranceMoney').val()==""?0:jQuery('#insuranceMoney').val();
	var a2 = jQuery('#luqiaoMoney').val()==""?0:jQuery('#luqiaoMoney').val();
	var a3 = jQuery('#oilMoney').val()==""?0:jQuery('#oilMoney').val();
	var a4 = jQuery('#roadToll').val()==""?0:jQuery('#roadToll').val();
	var a5 = jQuery('#parkingMoney').val()==""?0:jQuery('#parkingMoney').val();
	var a6 = jQuery('#maintenanceMoney').val()==""?0:jQuery('#maintenanceMoney').val();
	var a7 = jQuery('#purchasesMoney').val()==""?0:jQuery('#purchasesMoney').val();
	var a8 = jQuery('#limitedMoney').val()==""?0:jQuery('#limitedMoney').val();
	sum = parseFloat(a1) + parseFloat(a2)+parseFloat(a3) + parseFloat(a4)+parseFloat(a5) + parseFloat(a6)+parseFloat(a7) + parseFloat(a8);
	jQuery('#CarMoneyAll').val(sum);
	jQuery('#motorMoney').val(sum);
	OtherMoneyAllSum();
}
function OtherMoneyAllSum() {
	var sum = 0;
	var a1 = jQuery('#bidDocumentMoney').val()==""?0:jQuery('#bidDocumentMoney').val();
	var a2 = jQuery('#bidServiceMoney').val()==""?0:jQuery('#bidServiceMoney').val();
	var a3 = jQuery('#retransmissionMoney').val()==""?0:jQuery('#retransmissionMoney').val();
	var a4 = jQuery('#postageMoney').val()==""?0:jQuery('#postageMoney').val();
	var a5 = jQuery('#subscriptionMoney').val()==""?0:jQuery('#subscriptionMoney').val();
	var a6 = jQuery('#officeSuppliesMoney').val()==""?0:jQuery('#officeSuppliesMoney').val();
	var a7 = jQuery('#WithdrawalProcedureMoney').val()==""?0:jQuery('#WithdrawalProcedureMoney').val();
	var a8 = jQuery('#maintenanceCostMoney').val()==""?0:jQuery('#maintenanceCostMoney').val();
	var a9 = jQuery('#officeMoney').val()==""?0:jQuery('#officeMoney').val();
	var a10 = jQuery('#holidayMoney').val()==""?0:jQuery('#holidayMoney').val();
	var a11 = jQuery('#motorMoney').val()==""?0:jQuery('#motorMoney').val();
	var a12 = jQuery('#otherChargesMoney').val()==""?0:jQuery('#otherChargesMoney').val();
	sum = parseFloat(a1) + parseFloat(a2) + parseFloat(a3) + parseFloat(a4) + parseFloat(a5) + parseFloat(a6) + parseFloat(a7) + parseFloat(a8) + parseFloat(a9) + parseFloat(a10) + parseFloat(a11) + parseFloat(a12);
	jQuery('#OtherMoneyAll').val(sum);
	jQuery('#basicOtherMoney').val(sum);
	basicMoneyAllSum();
}
function basicMoneyAllSum() {
	var sum = 0;
	var a1 = jQuery('#loanMaoney').val()==""?0:jQuery('#loanMaoney').val();
	var a2 = jQuery('#travelMoney').val()==""?0:jQuery('#travelMoney').val();
	var a3 = jQuery('#hotelMoney').val()==""?0:jQuery('#hotelMoney').val();
	var a4 = jQuery('#subsidyMoney').val()==""?0:jQuery('#subsidyMoney').val();
	var a5 = jQuery('#entertainmentMoney').val()==""?0:jQuery('#entertainmentMoney').val();
	var a6 = jQuery('#projectFeeMoney').val()==""?0:jQuery('#projectFeeMoney').val();
	var a7 = jQuery('#telephoneMoney').val()==""?0:jQuery('#telephoneMoney').val();
	var a8 = jQuery('#taxiFareMoney').val()==""?0:jQuery('#taxiFareMoney').val();
	var a9 = jQuery('#salaryBonusMoney').val()==""?0:jQuery('#salaryBonusMoney').val();
	var a10 = jQuery('#amountChargeMoney').val()==""?0:jQuery('#amountChargeMoney').val();
	var a11 = jQuery('#basicOtherMoney').val()==""?0:jQuery('#basicOtherMoney').val();
	sum = parseFloat(a1) + parseFloat(a2) + parseFloat(a3) + parseFloat(a4) + parseFloat(a5) + parseFloat(a6) + parseFloat(a7) + parseFloat(a8) + parseFloat(a9) + parseFloat(a10) + parseFloat(a11);
	jQuery('#basicMoneySum').val(sum);
}

jQuery('.savePayBtn').on('click', function () {
	if(jQuery("#myMoneyAll") && !jQuery("#myMoneyAll").Validform({tiptype:3, showAllError:true}).check(false)){
        return;
    }
	var continuelife = jQuery('#continuelife').val();
	var buyer = jQuery('#buyer').val();
	if(continuelife!=""&&buyer!=""){
		var OutStartDate = jQuery('#OutStartDate').val();
		var BackDate = jQuery('#BackDate').val();
		var OutDays = jQuery('#OutDays').val();
		var asset = jQuery('#asset').val();
		var assetName = jQuery('#asset').find("option:selected").text();
		var applyArea = jQuery('#applyArea').val();
		var continuelife = jQuery('#continuelife').val();
		var breakDuty = jQuery('#breakDuty').val();
		var memo = jQuery('#memo').val();
		
		var rentMoney = jQuery('#rentMoney').val()==""?0:jQuery('#rentMoney').val();
		var waterMoney = jQuery('#waterMoney').val()==""?0:jQuery('#waterMoney').val();
		var wuguanMoney = jQuery('#wuguanMoney').val()==""?0:jQuery('#wuguanMoney').val();
		var banTelephoneMoney = jQuery('#banTelephoneMoney').val()==""?0:jQuery('#banTelephoneMoney').val();
		var shoppingMoney = jQuery('#shoppingMoney').val()==""?0:jQuery('#shoppingMoney').val();
		var otherMoney = jQuery('#otherMoney').val()==""?0:jQuery('#otherMoney').val();
		var insuranceMoney = jQuery('#insuranceMoney').val()==""?0:jQuery('#insuranceMoney').val();
		var luqiaoMoney = jQuery('#luqiaoMoney').val()==""?0:jQuery('#luqiaoMoney').val();
		var oilMoney = jQuery('#oilMoney').val()==""?0:jQuery('#oilMoney').val();
		var roadToll = jQuery('#roadToll').val()==""?0:jQuery('#roadToll').val();
		var parkingMoney = jQuery('#parkingMoney').val()==""?0:jQuery('#parkingMoney').val();
		var maintenanceMoney = jQuery('#maintenanceMoney').val()==""?0:jQuery('#maintenanceMoney').val();
		var purchasesMoney = jQuery('#purchasesMoney').val()==""?0:jQuery('#purchasesMoney').val();
		var limitedMoney = jQuery('#limitedMoney').val()==""?0:jQuery('#limitedMoney').val();
		var bidDocumentMoney = jQuery('#bidDocumentMoney').val()==""?0:jQuery('#bidDocumentMoney').val();
		var bidServiceMoney = jQuery('#bidServiceMoney').val()==""?0:jQuery('#bidServiceMoney').val();
		var retransmissionMoney = jQuery('#retransmissionMoney').val()==""?0:jQuery('#retransmissionMoney').val();
		var postageMoney = jQuery('#postageMoney').val()==""?0:jQuery('#postageMoney').val();
		var subscriptionMoney = jQuery('#subscriptionMoney').val()==""?0:jQuery('#subscriptionMoney').val();
		var officeSuppliesMoney = jQuery('#officeSuppliesMoney').val()==""?0:jQuery('#officeSuppliesMoney').val();
		var WithdrawalProcedureMoney = jQuery('#WithdrawalProcedureMoney').val()==""?0:jQuery('#WithdrawalProcedureMoney').val();
		var maintenanceCostMoney = jQuery('#maintenanceCostMoney').val()==""?0:jQuery('#maintenanceCostMoney').val();
		var officeMoney = jQuery('#officeMoney').val()==""?0:jQuery('#officeMoney').val();
		var holidayMoney = jQuery('#holidayMoney').val()==""?0:jQuery('#holidayMoney').val();
		var motorMoney = jQuery('#motorMoney').val()==""?0:jQuery('#motorMoney').val();
		var otherChargesMoney = jQuery('#otherChargesMoney').val()==""?0:jQuery('#otherChargesMoney').val();
		var loanMaoney = jQuery('#loanMaoney').val()==""?0:jQuery('#loanMaoney').val();
		var travelMoney = jQuery('#travelMoney').val()==""?0:jQuery('#travelMoney').val();
		var hotelMoney = jQuery('#hotelMoney').val()==""?0:jQuery('#hotelMoney').val();
		var subsidyMoney = jQuery('#subsidyMoney').val()==""?0:jQuery('#subsidyMoney').val();
		var entertainmentMoney = jQuery('#entertainmentMoney').val()==""?0:jQuery('#entertainmentMoney').val();
		var projectFeeMoney = jQuery('#projectFeeMoney').val()==""?0:jQuery('#projectFeeMoney').val();
		var telephoneMoney = jQuery('#telephoneMoney').val()==""?0:jQuery('#telephoneMoney').val();
		var taxiFareMoney = jQuery('#taxiFareMoney').val()==""?0:jQuery('#taxiFareMoney').val();
		var salaryBonusMoney = jQuery('#salaryBonusMoney').val()==""?0:jQuery('#salaryBonusMoney').val();
		var amountChargeMoney = jQuery('#amountChargeMoney').val()==""?0:jQuery('#amountChargeMoney').val();
		var basicOtherMoney = jQuery('#basicOtherMoney').val()==""?0:jQuery('#basicOtherMoney').val();
		
		var url = window.rootPath+'/ui/myMoneyAll/saveMyMoneyAll';
		
		var d={
				"outStartDate":OutStartDate,
				"backDate":BackDate,
				"outDays":OutDays,
				"applyUser":asset,
				"applyUserName":assetName,
				"applyDept":continuelife,
				"applyArea":applyArea,
				"applyDate":buyer,
				"useContent":breakDuty,
				"memo":memo,//备注
				"loanMaoney":loanMaoney,//基本费用
				"travelMoney":travelMoney,
				"hotelMoney":hotelMoney,
				"subsidyMoney":subsidyMoney,
				"entertainmentMoney":entertainmentMoney,
				"projectFeeMoney":projectFeeMoney,
				"telephoneMoney":telephoneMoney,
				"taxiFareMoney":taxiFareMoney,
				"salaryBonusMoney":salaryBonusMoney,
				"amountChargeMoney":amountChargeMoney,
				"bidDocumentMoney":bidDocumentMoney,//其他费用
				"bidServiceMoney":bidServiceMoney,
				"retransmissionMoney":retransmissionMoney,
				"postageMoney":postageMoney,
				"subscriptionMoney":subscriptionMoney,
				"officeSuppliesMoney":officeSuppliesMoney,
				"withdrawalProcedureMoney":WithdrawalProcedureMoney,
				"maintenanceCostMoney":maintenanceCostMoney,
				"officeMoney":officeMoney,
				"holidayMoney":holidayMoney,
				"motorMoney":motorMoney,
				"otherChargesMoney":otherChargesMoney,
				"insuranceMoney":insuranceMoney,//小车费用
				"luqiaoMoney":luqiaoMoney,
				"oilMoney":oilMoney,
				"roadToll":roadToll,
				"parkingMoney":parkingMoney,
				"maintenanceMoney":maintenanceMoney,
				"purchasesMoney":purchasesMoney,
				"limitedMoney":limitedMoney,
				"basicOtherMoney":basicOtherMoney,//办事处费用
				"rentMoney":rentMoney,
				"waterMoney":waterMoney,
				"wuguanMoney":wuguanMoney,
				"banTelephoneMoney":banTelephoneMoney,
				"shoppingMoney":shoppingMoney,
				"otherMoney":otherMoney,
		};
		jQuery(".btn").attr("disabled", true);
		jQuery.ajax({
	          type: 'post',
	          url: encodeURI(url),
	          data: JSON.stringify(d),
	          dataType: 'json',
	          contentType: 'application/json;charset=utf-8',
	          success: function (data) {
	        	  var continuelife = jQuery("#continuelife").val();
	        	  jQuery("input").val("");
	        	  jQuery("select").val("");
	        	  jQuery("textarea").val("");
	        	  jQuery("#continuelife").val(continuelife);
	        	  jQuery(".btn").attr("disabled", false);
	          }
    	});
	}else{
		alert("请输入申请部门和时间！")
	}
});